package com.yuexunit.operationman.nbsy.module.Login.presenter.impl;

import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.Login.bean.PatientBean;
import com.yuexunit.operationman.nbsy.module.Login.model.ISearchModel;
import com.yuexunit.operationman.nbsy.module.Login.presenter.ISearchPresenter;
import com.yuexunit.operationman.nbsy.module.Login.ui.view.ISearchView;

import org.kymjs.kjframe.ui.ViewInject;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2017/7/12.
 */
public class SearchPresenter implements ISearchPresenter{
    private ISearchModel mModel;
    private ISearchView mView;

    public SearchPresenter(ISearchView view,ISearchModel model){
        mModel=model;
        mView=view;
    }


    @Override
    public void getPatientDate(String inHospitalNo) {
        mModel.getPatientDate(inHospitalNo)
                .subscribeOn(Schedulers.io())
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {
//                        log.info("UserPresenter_doInLogin_SHOW_DIALOG");
                        mView.loadingDialogStatus(AppConfig.SHOW_DIALOG);
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<PatientBean>() {
                    @Override
                    public void onCompleted() {
                        mView.loadingDialogStatus(AppConfig.DISMISS_DIALOG);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.loadingDialogStatus(AppConfig.DISMISS_DIALOG);
                        ViewInject.toast(e.getMessage());
                    }

                    @Override
                    public void onNext(PatientBean patientBean) {
                        mView.getPatientDate(patientBean);
                    }
                });
    }
}
